package com.google.coffeeshop.dao;

import javax.persistence.EntityManager;

import com.google.coffeeshop.dao.impl.ConfigurationDAOImpl;
import com.google.coffeeshop.dao.impl.EmployeeDAOImpl;
import com.google.coffeeshop.dao.impl.GlobalStatusDAOImpl;
import com.google.coffeeshop.dao.impl.InvoiceDAOImpl;
import com.google.coffeeshop.dao.impl.InvoiceLineDAOImpl;
import com.google.coffeeshop.dao.impl.OrderDAOImpl;
import com.google.coffeeshop.dao.impl.OrderLineDAOImpl;
import com.google.coffeeshop.dao.impl.ProductDAOImpl;
import com.google.coffeeshop.dao.impl.ProductGroupDAOImpl;
import com.google.coffeeshop.dao.impl.ProductPriceDAOImpl;
import com.google.coffeeshop.dao.impl.ReceiptNoteDAOImpl;
import com.google.coffeeshop.dao.impl.ReceiptNoteLineDAOImpl;
import com.google.coffeeshop.dao.impl.RoleDAOImpl;
import com.google.coffeeshop.dao.impl.SeatDAOImpl;
import com.google.coffeeshop.dao.impl.UserDAOImpl;
import com.googlecode.genericdao.dao.jpa.GenericDAOImpl;
import com.googlecode.genericdao.search.jpa.JPAAnnotationMetadataUtil;
import com.googlecode.genericdao.search.jpa.JPASearchProcessor;

public class DAOFactory {
	static public RoleDAO createRoleDAO(EntityManager entityManager) {
		RoleDAOImpl daoImpl = new RoleDAOImpl();
		setUpGenericDAOImpl(daoImpl, entityManager);
		return daoImpl;
	}
	static public UserDAO createUserDAO(EntityManager entityManager) {
		UserDAOImpl daoImpl = new UserDAOImpl();
		setUpGenericDAOImpl(daoImpl, entityManager);
		return daoImpl;
	}
	static public EmployeeDAO createEmployeeDAO(EntityManager entityManager) {
		EmployeeDAOImpl daoImpl = new EmployeeDAOImpl();
		setUpGenericDAOImpl(daoImpl, entityManager);
		return daoImpl;
	}
	static public InvoiceDAO createInvoiceDAO(EntityManager entityManager) {
		InvoiceDAOImpl daoImpl = new InvoiceDAOImpl();
		setUpGenericDAOImpl(daoImpl, entityManager);
		return daoImpl;
	}
	static public InvoiceLineDAO createInvoiceLineDAO(EntityManager entityManager) {
		InvoiceLineDAOImpl daoImpl = new InvoiceLineDAOImpl();
		setUpGenericDAOImpl(daoImpl, entityManager);
		return daoImpl;
	}
	static public OrderDAO createOrderDAO(EntityManager entityManager) {
		OrderDAOImpl dapImpl = new OrderDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	static public OrderLineDAO createOrderLineDAO(EntityManager entityManager) {
		OrderLineDAOImpl dapImpl = new OrderLineDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	static public ProductDAO createProductDAO(EntityManager entityManager) {
		ProductDAOImpl dapImpl = new ProductDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	static public ProductGroupDAO createProductGroupDAO(EntityManager entityManager) {
		ProductGroupDAOImpl dapImpl = new ProductGroupDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	static public ProductPriceDAO createProductPriceDAO(EntityManager entityManager) {
		ProductPriceDAOImpl dapImpl = new ProductPriceDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	static public ReceiptNoteDAO createReceiptNoteDAO(EntityManager entityManager) {
		ReceiptNoteDAOImpl dapImpl = new ReceiptNoteDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	static public ReceiptNoteLineDAO createReceiptNoteLineDAO(EntityManager entityManager) {
		ReceiptNoteLineDAOImpl dapImpl = new ReceiptNoteLineDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	static public SeatDAO createSeatDAO(EntityManager entityManager) {
		SeatDAOImpl dapImpl = new SeatDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	static public GlobalStatusDAO createGlobalStatusDAO(EntityManager entityManager) {
		GlobalStatusDAOImpl dapImpl = new GlobalStatusDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	static public ConfigurationDAO createConfigurationDAO(EntityManager entityManager) {
		ConfigurationDAOImpl dapImpl = new ConfigurationDAOImpl();
		setUpGenericDAOImpl(dapImpl, entityManager);
		return dapImpl;
	}
	@SuppressWarnings("rawtypes")
	private static void setUpGenericDAOImpl(GenericDAOImpl genericDAOImpl, EntityManager entityManager) {
		genericDAOImpl.setEntityManager(entityManager);
		genericDAOImpl.setSearchProcessor(new JPASearchProcessor(new JPAAnnotationMetadataUtil()));
	}
}
